package com.example.aihub.repository;

import com.example.aihub.entity.Post;
import com.example.aihub.entity.PostCategory;
import com.example.aihub.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PostRepository extends JpaRepository<Post, Long> {
    List<Post> findByUser(User user);
    List<Post> findByStatus(Post.PostStatus status);
    List<Post> findTop10ByStatusOrderByCreatedAtDesc(Post.PostStatus status);
    List<Post> findByTitleContainingIgnoreCase(String keyword);
    
    // 添加按点赞数排序的查询方法
    List<Post> findTop5ByStatusOrderByLikeCountDesc(Post.PostStatus status);
    
    // 添加按分类查询帖子的方法
    List<Post> findByCategory(PostCategory category);
    List<Post> findByCategoryAndStatusOrderByCreatedAtDesc(PostCategory category, Post.PostStatus status);
}